<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateUserTable extends Migrator
{
    const TBL_NAME = 'user';

    public function change()
    {
        // create the table
        $table  =  $this->table(addTablePrefix(self::TBL_NAME),[
            'engine'=>'InnoDB',
            'comment' => '用户表',
            'signed' => false
        ]);
        $table
            ->addColumn('username', 'string',array('limit'  =>  15,'default'=>'','comment'=>'用户名'))
            ->addColumn('email', 'string',array('limit'  =>  64,'default'=>'','comment'=>'邮箱'))
            ->addColumn('password_hash', 'string',array('limit'  =>  125,'default'=>'','comment'=>'密码'))
            ->addColumn('mobile', 'string',array('limit'  =>  11, 'null'=>true,'comment'=>'手机号'))
            ->addColumn('nickname', 'string',array('limit' => 12, 'null'=>true,'comment'=>'昵称'))
            ->addColumn('avatar', 'string',array('limit' => 125, 'default'=>'','comment'=>'头像'))
            ->addColumn('status', 'integer',array('signed' => false, 'default'=>0,'comment'=>'状态'))
            ->addColumn('auth_key', 'string',array('limit'=>125,'default'=>'','comment'=>'免登录凭证'))
            ->addColumn('password_reset_token', 'string',array('limit' => 125, 'default'=>'','comment'=>'密码重置凭证'))
            ->addColumn('last_time', 'integer',array('signed' => false, 'default'=>0,'comment'=>'状态'))
            ->addColumn('create_time', 'integer',array('signed' => false, 'default'=>0,'comment'=>'创建时间'))
            ->addColumn('update_time', 'integer',array('signed' => false, 'default'=>0,'comment'=>'修改时间'))



            ->addIndex(array('username'), array('unique'  =>  true))
            ->addIndex(array('email'), array('unique'  =>  true))
            ->addIndex(array('mobile'), array('unique'  =>  true))
            ->addIndex(array('nickname'), array('unique'  =>  true))

            ->addIndex(array('create_time'))
            ->create();
    }
}
